package b1.mobile.blackberry.entity;

import org.json.me.JSONObject;

import b1.mobile.blackberry.lang.CommonConstant;

/**
 * <pre>
 * <b>JSON</b> 
 * {
 * 	"CardCode":"V10000",
 *	"CardName":"Acme Associates bv",
 *	"CardType":"Vendor",
 *	"PhoneNum":"(291) 917-37",
 *	"Email":"info@acme.net",
 *	"Country":"US",
 *	"State":"PA",
 *	"City":"Manchester",
 *	"Street":"600 Eastern Blvd",
 *	"ZipCode":"03101",
 *	"ContactPerson":"Rena Marrazzo",
 * 	"LastCall":"2011-09-28 20:02",
 * 	"CreditLimit":"0.00 $",
 *	"WebSite":"www.acme.net",
 *	"AccountBalance":"-336,895.69 $",
 *	"ContactsCount":"2"
 * }
 * <b>Property:</b>
 * 	Address = street + state + zip + country
 * </pre>
 */
public class BusinessPartnerEntity extends GenericEntity {
	public static String JK_CARDCODE = "CardCode";
	public static String JK_CARDNAME = "CardName";
	public static String JK_CARDTYPE = "CardType";
	public static String JK_PHONENUM = "PhoneNum";
	public static String JK_EMAIL = "Email";
	public static String JK_COUNTRY = "Country";
	public static String JK_STATE = "State";
	public static String JK_STREET = "Street";
	public static String JK_ZIPCODE = "ZipCode";
	public static String JK_CONTACTPERSON = "ContactPerson";
	public static String JK_LASTCALL = "LastCall";
	public static String JK_CREDITLIMT = "CreditLimit";
	public static String JK_WEBSITE = "WebSite";
	public static String JK_ACCOUNTBAL = "AccountBalance";
	public static String JK_CONTACTSCOUNT = "ContactsCount";
	
	public BusinessPartnerEntity(JSONObject obj){
		super(obj);
	}

	public String getAddress(){
		StringBuffer address = new StringBuffer();
		
		String country = getStringProperty(JK_COUNTRY);
		String state = getStringProperty(JK_STATE);
		String street = getStringProperty(JK_STREET);
		String zip = getStringProperty(JK_ZIPCODE);
		
		address.append(street);
		address.append(" ");
		address.append(state);
		address.append(" ");
		address.append(zip);
		address.append(" ");
		address.append(country);	
		
		return address.toString();
	}
	
	public int getType(){
		int type = CommonConstant.BP_TYPE_VENDOR;
		String typeString = getStringProperty(JK_CARDTYPE);
		if(typeString.equals("C")){
			type = CommonConstant.BP_TYPE_CUSTOMER;
		} else if (typeString.equals("L")){
			type = CommonConstant.BP_TYPE_LEAD;
		}
		return type;
	}
	
	public String getName(){
		return getStringProperty(JK_CARDNAME);
	}
	
	public String getCode(){
		return getStringProperty(JK_CARDCODE);
	}
	
}
